package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("admin/order")
@Api(tags = "管理员订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索·")
    public Result<PageResult> selectOrder(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.selectOrder(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/statistics")
    @ApiOperation("订单状态查询")
    public Result<OrderStatisticsVO> status(){
        OrderStatisticsVO statisticsVO = orderService.selectStatus();
        return Result.success(statisticsVO);
    }

    /**
    * 查看订单详情
    * @param id
    * @return Result<OrderVO>
    */
    @GetMapping("/details/{id}")
    public Result<OrderVO> detail(@PathVariable("id") Long id){
        OrderVO result = orderService.orderDetail(id);
        return Result.success(result);
    }

    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒单
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
    * 派送
    * @param id
    * @return Result
    */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result finish(@PathVariable("id") Long id){
        orderService.finish(id);
        return Result.success();
    }
}

